package com.feshfans.controller.special;

import com.feshfans.controller.Controller;
import com.feshfans.xmpp.client.RoomClient;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.TextField;
import org.jivesoftware.smack.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class AddRoomController extends Controller<Void> {

    private static final Logger Log = LoggerFactory.getLogger(AddRoomController.class);

    private RoomClient roomClient;

    @FXML
    private TextField roomNameTextField;

    public AddRoomController(){
        roomClient = RoomClient.getInstance();
    }

    @FXML
    public void addRoomConfirmClicked(ActionEvent event){
        String roomName = roomNameTextField.getText();
        if(StringUtils.isNullOrEmpty(roomName)){
            Alert alert = new Alert(Alert.AlertType.ERROR);
            alert.setContentText("添加房间错误");
            alert.showAndWait();
            return;
        }

        try {
            roomClient.createReservedRoom(roomName);
            return;
        } catch (Exception e) {
            Log.error("创建房间失败,name:{}",roomName,e);
            Alert alert = new Alert(Alert.AlertType.ERROR);
            alert.setContentText("创建房间失败");
            alert.showAndWait();
            return;

        }
    }

}
